From 4996764b7ebe0048cab17e20902dd16f64240713 Mon Sep 17 00:00:00 2001 From: Robert Lipe Date: Wed, 12 Apr 2023 17:51:17 -0500 Subject: [PATCH] Make locale debugging a compile-time constexpr debug instead of #ifdef. (#1011) * Make locale debugging a compile-time constexpr debug instead of #ifdef. * Ignore *.a in git so a branch change work more effortlessly on MacOS. (Yeah, not part of this CL...) Co-authored-by: GPSBabel <12013583+GPSBabelDeveloper@users.noreply.github.com> --- .gitignore | 1 + main.cc | 41 ++++++++++++++++++++--------------------- 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/.gitignore b/.gitignore index a96f4c795..3ec3a113c 100644 --- a/.gitignore +++ b/.gitignore @@ -23,6 +23,7 @@ /*.gcno /*.gcov *.o +*.a .ninja_deps .ninja_log build.ninja diff --git a/main.cc b/main.cc index af61aa3e4..da928332e 100644 --- a/main.cc +++ b/main.cc @@ -23,8 +23,6 @@ #include // for printf, fflush, fgetc, fprintf, stderr, stdin, stdout #include // for strcmp -#include // for QByteArray -#include // for QChar #include // for QCoreApplication #include // for QFile #include // for QIODevice::ReadOnly @@ -57,6 +55,8 @@ #include "src/core/usasciicodec.h" // for UsAsciiCodec #include "vecs.h" // for Vecs +static constexpr int DEBUG_LOCALE = 0; + #define MYNAME "main" // be careful not to advance argn passed the end of the list, i.e. ensure argn < qargs.size() #define FETCH_OPTARG qargs.at(argn).size() > 2 ? QString(qargs.at(argn)).remove(0,2) : qargs.size()>(argn+1) ? qargs.at(++argn) : QString() @@ -707,9 +707,9 @@ main(int argc, char* argv[]) #error MSVC 2015 and earlier are not supported. Please use MSVC 2017 or MSVC 2019. #endif -#ifdef DEBUG_LOCALE - printf("Initial locale: %s\n",setlocale(LC_ALL, NULL)); -#endif + if constexpr (DEBUG_LOCALE) { + printf("Initial locale: %s\n",setlocale(LC_ALL, NULL)); + } // Create a QCoreApplication object to handle application initialization. // In addition to being useful for argument decoding, the creation of a @@ -724,33 +724,32 @@ main(int argc, char* argv[]) // may result in LC_ALL being set to the native environment // as opposed to the initial default "C" locale. // This was demonstrated with Qt5 on Mac OS X. -#ifdef DEBUG_LOCALE - printf("Locale after initial setup: %s\n",setlocale(LC_ALL, NULL)); -#endif + if constexpr (DEBUG_LOCALE) { + printf("Locale after initial setup: %s\n",setlocale(LC_ALL, NULL)); + } // As recommended in QCoreApplication reset the locale to the default. // Note the documentation says to set LC_NUMERIC, but QCoreApplicationPrivate::initLocale() // actually sets LC_ALL. // Perhaps we should restore LC_ALL instead of only LC_NUMERIC. if (strcmp(setlocale(LC_NUMERIC,nullptr), "C") != 0) { -#ifdef DEBUG_LOCALE - printf("Resetting LC_NUMERIC\n"); -#endif + if constexpr (DEBUG_LOCALE) { + printf("Resetting LC_NUMERIC\n"); + } setlocale(LC_NUMERIC,"C"); -#ifdef DEBUG_LOCALE - printf("LC_ALL: %s\n",setlocale(LC_ALL, NULL)); -#endif + if constexpr (DEBUG_LOCALE) { + printf("LC_ALL: %s\n",setlocale(LC_ALL, NULL)); + } } /* reset LC_TIME for strftime */ if (strcmp(setlocale(LC_TIME,nullptr), "C") != 0) { -#ifdef DEBUG_LOCALE - printf("Resetting LC_TIME\n"); -#endif + if constexpr (DEBUG_LOCALE) { + printf("Resetting LC_TIME\n"); + } setlocale(LC_TIME,"C"); -#ifdef DEBUG_LOCALE - printf("LC_ALL: %s\n",setlocale(LC_ALL, NULL)); -#endif + if constexpr (DEBUG_LOCALE) { + printf("LC_ALL: %s\n",setlocale(LC_ALL, NULL)); + } } - qInstallMessageHandler(MessageHandler); (void) new gpsbabel::UsAsciiCodec(); /* make sure a US-ASCII codec is available */ -- 2.30.2